package com.atguigu.gulimall.seckill.schedule;

import com.atguigu.gulimall.seckill.service.SecKillService;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @author: xuesm
 * @date: 2025/3/14 22:42
 */
@Slf4j
@Service
public class SecKillSkuScheduled {

    @Autowired
    RedissonClient redissonClient;

    @Autowired
    SecKillService secKillService;

    private final String upload_lock = "seckill:upload:lock:";
//    @Scheduled(cron = "0 0/1 * * * ?")
    public void uploadSecKillSkuLast3Days(){

        RLock lock = redissonClient.getLock(upload_lock);
        lock.lock(10, TimeUnit.SECONDS);
        try {
            secKillService.uploadSecKillSkuLast3Days();
        }finally {
            lock.unlock();
        }
    }
}
